package com.party.admin.web.controller.dbAnalyze;

import com.google.common.base.Strings;
import com.google.common.collect.Maps;
import com.party.admin.biz.dbAnalyze.DbAnalyzeBizService;
import com.party.admin.web.dto.AjaxResult;
import com.party.admin.web.dto.output.dbAnalyze.DbAnalyzeCountOutput;
import com.party.admin.web.dto.output.dbAnalyze.DbAnalyzeOutput;
import com.party.common.paging.Page;
import com.party.core.model.dbAnalyze.DbAnalyze;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;
import java.util.List;

/**
 * Created by wei.li
 *
 * @date 2017/8/3 0003
 * @time 11:22
 */

@Controller
@RequestMapping(value = "/db/analyze")
public class DbAnalyzeController {

    @Autowired
    private DbAnalyzeBizService dbAnalyzeBizService;


    /**
     * 分页查询
     * @param dbAnalyze 分析
     * @param page 分页参数
     * @return 数据列表
     */
    @RequestMapping(value = "list")
    public ModelAndView list(DbAnalyze dbAnalyze, Page page){
        page.setLimit(20);
        ModelAndView modelAndView = new ModelAndView("/dbAnalyze/dbAnalyze");
        List<DbAnalyzeOutput> list = dbAnalyzeBizService.list(dbAnalyze, page);
        modelAndView.addObject("list", list);
        modelAndView.addObject("page", page);
        return modelAndView;
    }

    /**
     * 列表
     * @param tableName 表名
     * @return 交互数据
     */
    @ResponseBody
    @RequestMapping(value = "countList")
    public AjaxResult countList(String tableName){
        AjaxResult ajaxResult = new AjaxResult();
        DbAnalyzeCountOutput dbAnalyzeCountOutput = new DbAnalyzeCountOutput();
        List<String> dayList = dbAnalyzeBizService.listDay();
        tableName = Strings.isNullOrEmpty(tableName) ? "member" : tableName;
        List<Integer> dataList = dbAnalyzeBizService.countList(tableName);
        dbAnalyzeCountOutput.setDataList(dataList);
        dbAnalyzeCountOutput.setDayList(dayList);
        dbAnalyzeCountOutput.setTableName(tableName);
        ajaxResult.setData(dbAnalyzeCountOutput);
        return ajaxResult;
    }
}
